<%@page import="org.quickbundle.orgauth.cache.RmPartyTypeCache"%>
<%@page import="org.quickbundle.orgauth.IOrgauthConstants"%>
<%@page import="com.dfhc.rm.user.IUserConstants"%>
<%@page import="org.quickbundle.orgauth.rmuser.util.IRmUserConstants"%>
<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="/favicon.ico" />

<!-- 全局js 和css包 -->
<%@ include file="/jsp/include/web/new/global.jsp" %>
<title>用户管理</title>
<!--/meta 作为公共模版分离出去-->

<link rel="stylesheet" href="<%=request.getContextPath() %>/css/ztree/demo.css" type="text/css">
<link rel="stylesheet" href="<%=request.getContextPath() %>/css/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="<%=request.getContextPath() %>/js/ztree/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/ztree/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/new/newjs/WdatePicker.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/h-ui.admin/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/js/h-ui.admin/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/js/h-ui.admin/jquery.validation/1.14.0/messages_zh.js"></script> 

<title>添加用户 </title>

<%@ taglib uri="/dfhc" prefix="dfhc" %>
</head>
<script type="text/javascript">
		var child_party_id='';
		var child_party_name='';
		var child_party_code='';
		var setting = {
			async: {
			enable: true,
			url:"<%=request.getContextPath()%>/pubController/ajaxGetParty?is_allow_hanging_user=1",
			autoParam:["child_party_code"],
			otherParam:{},
			dataFilter: filter
		  },
		  callback: {
			  beforeClick: beforeClick1,
			  beforeAsync: beforeAsync,
			  onAsyncError: onAsyncError,
			  onAsyncSuccess: onAsyncSuccess
			  }
		};
		function filter(treeId, parentNode, childNodes) {
			if (!childNodes) return null;			
			var childNodes= childNodes.trees;
			if (!childNodes) return null;
			for (var i=0, l=childNodes.length; i<l; i++) {		
				childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
				if(childNodes[i].is_leaf=='1'){
					childNodes[i].isParent=false;
				}else{
					childNodes[i].isParent=true;
				}
			}
			return childNodes;
		}
		function beforeClick1(treeId, treeNode) {
			child_party_id = treeNode.child_party_id;
			child_party_name = treeNode.name;
			child_party_code = treeNode.child_party_code; 
			$("#organizationName").val(child_party_name);
			$("#organizationId").val(child_party_id);
			if(treeNode.is_leaf=='1'){
					treeNode.isParent=false;
				}else{
					treeNode.isParent=true;
				}
    	   $("#organizationContent").css({
    		left:0,
    		top:0,
    		display:"none",
    		width:0
    	   }).fadeOut("fast");				
			if (!treeNode.isParent) {
				return false;
			} else {
				return true;
			}
		}
		var log, className = "dark";
		function beforeAsync(treeId, treeNode) {
			className = (className === "dark" ? "":"dark");
			showLog("[ "+getTime()+" beforeAsync ]&nbsp;&nbsp;&nbsp;&nbsp;" + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") );
			return true;
		}
		function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
			showLog("[ "+getTime()+" onAsyncError ]&nbsp;&nbsp;&nbsp;&nbsp;" + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") );
		}
		function onAsyncSuccess(event, treeId, treeNode, msg) {
			showLog("[ "+getTime()+" onAsyncSuccess ]&nbsp;&nbsp;&nbsp;&nbsp;" + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") );
		}
		
		function showLog(str) {
			if (!log) log = $("#log");
			log.append("<li class='"+className+"'>"+str+"</li>");
			if(log.children("li").length > 8) {
				log.get(0).removeChild(log.children("li")[0]);
			}
		}
		function getTime() {
			var now= new Date(),
			h=now.getHours(),
			m=now.getMinutes(),
			s=now.getSeconds(),
			ms=now.getMilliseconds();
			return (h+":"+m+":"+s+ " " +ms);
		}	   
</script>		
<body>
	<div style="z-index: 9999; display: none;" id="organizationContent">
		<div class="zTreeDemoBackground">
			<ul id="treeDemo" class="ztree"></ul>
		</div>
	</div>

	<article class="page-container">

	<form action="" method="post" class="form form-horizontal" id="form-member-add" >
		<input type="hidden" name="view_id" value="<%=IOrgauthConstants.PartyView.DEFAULT.id() %>" id="view_id"></input>
		<input type="hidden" name="isInherit" value="0"></input>
		<input type="hidden" name="party_type_id"  value="<%=IOrgauthConstants.Config.isUserRelationParty.value() && RmPartyTypeCache.getPartyType(IRmUserConstants.TABLE_NAME) != null ? RmPartyTypeCache.getPartyType(IRmUserConstants.TABLE_NAME).getId() : ""%>"/>	
		<input type="hidden" id="id" name="id" value="${bean.id}">
	    <dfhc:div templateId="h_ui_div_row_cl">
	    <dfhc:title templateId="h_ui_label_title"><dfhc:span templateId="h_ui_not_null_span"></dfhc:span><%=IRmUserConstants.TABLE_COLUMN_CHINESE.get("name")%>：</dfhc:title>	    
	    <dfhc:div templateId="h_ui_div_fromcontrol">	        
			<dfhc:input templateId="h_ui_input" value="${bean.name}" placeholder="" id="name" name="name"/>			
		</dfhc:div>	    		 
	    </dfhc:div>
		<dfhc:div templateId="h_ui_div_row_cl">
			<dfhc:title templateId="h_ui_label_title"><dfhc:span templateId="h_ui_not_null_span"></dfhc:span><%=IRmUserConstants.TABLE_COLUMN_CHINESE.get("lock_status")%>:</dfhc:title>
			<dfhc:div templateId="h_ui_div_fromcontrol">
				<dfhc:select templateId="h_ui_select" size="1" name="lock_status" id="lock_status" pleaseSelect="1" defaultValue="${bean.lock_status}" sqlOption="code" code="<%=IRmUserConstants.DICTIONARY_RM_LOCK_STATUS%>" />				
			</dfhc:div>
		</dfhc:div>
		<dfhc:div templateId="h_ui_div_row_cl">
			<dfhc:title templateId="h_ui_label_title"><dfhc:span templateId="h_ui_not_null_span"></dfhc:span><%=IRmUserConstants.TABLE_COLUMN_CHINESE.get("login_id")%>：</dfhc:title>
			<dfhc:div templateId="h_ui_div_fromcontrol">
				<dfhc:input templateId="h_ui_input" value="${bean.login_id}" placeholder="请输入登录名" id="loginId" name="loginId"/>
			</dfhc:div>
		</dfhc:div>
		<dfhc:div templateId="h_ui_div_row_cl">
			<dfhc:title templateId="h_ui_label_title"><dfhc:span templateId="h_ui_not_null_span"></dfhc:span><%=IRmUserConstants.TABLE_COLUMN_CHINESE.get("email")%>：</dfhc:title>
			<dfhc:div templateId="h_ui_div_fromcontrol">				
				<dfhc:input templateId="h_ui_input" value="${bean.email}" placeholder="@" id="email" name="email"/>
			</dfhc:div>
		</dfhc:div>
		<dfhc:div templateId="h_ui_div_row_cl">
			<dfhc:title templateId="h_ui_label_title"><dfhc:span templateId="h_ui_not_null_span"></dfhc:span><%=IRmUserConstants.TABLE_COLUMN_CHINESE.get("password")%>:</dfhc:title>
			<dfhc:div templateId="h_ui_div_fromcontrol"> 
				<dfhc:password templateId="h_ui_password" placeholder="请输入密码" id="password" name="password"/>
			</dfhc:div>
		</dfhc:div>
		<dfhc:div templateId="h_ui_div_row_cl">
			<dfhc:title templateId="h_ui_label_title"><dfhc:span templateId="h_ui_not_null_span"></dfhc:span>密码确认:</dfhc:title>
			<dfhc:div templateId="h_ui_div_fromcontrol"> 
				<dfhc:password templateId="h_ui_password"  placeholder="请输入确认密码" id="password2" name="password2"/>
			</dfhc:div>
		</dfhc:div>
		<dfhc:div templateId="h_ui_div_row_cl">
			<dfhc:title templateId="h_ui_label_title">所在组织：</dfhc:title>
			<dfhc:div templateId="h_ui_div_fromcontrol"> 
			<dfhc:input templateId="h_ui_input" value="${bean.attribute1}" placeholder="点击选择组织" id="organizationName" name="organizationName"  readonly="true" />
			<input type="hidden" id="organization_id" value="${bean.organization_id}" name="organization_id" >
			</dfhc:div>
		</dfhc:div>
		<dfhc:div templateId="h_ui_div_row_cl">
			<dfhc:title templateId="h_ui_label_title">描述：</dfhc:title>
			<dfhc:div templateId="h_ui_div_fromcontrol">			    
				<dfhc:textarea name="description" cols="" rows=""   placeholder="说点什么...最少输入10个字符" maxlength="100" templateId="h_ui_textarea" >${bean.description}</dfhc:textarea>				
			</dfhc:div>
		</dfhc:div>
		<dfhc:div templateId="h_ui_div_row_cl">
			<dfhc:title templateId="h_ui_label_title"><dfhc:span templateId="h_ui_not_null_span"></dfhc:span><%=IRmUserConstants.TABLE_COLUMN_CHINESE.get("admin_type")%>:</dfhc:title>
			<dfhc:div templateId="h_ui_div_fromcontrol">
				<dfhc:select templateId="h_ui_select" size="1" name="lockStatus" id="lockStatus" pleaseSelect="1" defaultValue="${bean.admin_type}" sqlOption="code" code="<%=IRmUserConstants.DICTIONARY_RM_ADMIN_TYPE%>" />				
			</dfhc:div>
		</dfhc:div>
		<dfhc:div templateId="h_ui_div_row_cl">
			<dfhc:div templateId="h_ui_div_pop_up_button">
				<dfhc:button templateId="h_ui_submit_button" />
			</dfhc:div>
		</dfhc:div>
	</form>
</article>



<script type="text/javascript">
$(function(){
	$.fn.zTree.init($("#treeDemo"), setting);
	//获取新id
	<c:if test="${empty bean}"> 
	$('#id').val(getNewId('<%=IRmUserConstants.TABLE_NAME%>'));
	</c:if>
	//点击选择组织,
    $('#organizationName').on('focus',function(){
    	var origanizationObj = $("#organizationName");
    	var organizationContentObj = $("#organizationContent");
    	var origanizationOffset = $("#organizationName").offset();
    	var top = (origanizationOffset.top + origanizationObj.outerHeight()-organizationContentObj.outerHeight())+"px";    	
    	$("#organizationContent").css({
    	left:origanizationOffset.left+"px",
    	top:(origanizationOffset.top -organizationContentObj.outerHeight())+80+"px",
    	display:"block",
    	width:(origanizationObj.outerWidth()-3)+"px",
    	position:"absolute"
    	}).slideDown("fast");
    	
    	$("body").bind("mousedown",function(){
    	   if(!(event.target.id =="organizationContent" || $(event.target).parents("#organizationContent").length>0)){
    	   $("#organizationContent").css({
    		left:0,
    		top:0,
    		display:"none",
    		width:0
    	   }).fadeOut("fast");
    	   }
    	});
    });
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-member-add").validate({
		rules:{
			name:{
				required:true,
				minlength:2,
				maxlength:200
			},
			lockStatus:{
				required:true,
			},
			loginId:{			
				required:true,
				minlength:2,
				maxlength:200
			},
			email:{
				required:true,
				email:true,
			},
			password:{
				required:true,				
				minlength:6,
			},
			password2:{
				required:true,
				minlength:6,
				equalTo: "#password"
			},
		},
 		messages: {
	      name: {
	        required: "请输入用户名",
	        minlength: "用户名必需由两个字母组成",
			maxlength: "用户名最大长度为200个字母"
	      },
		  lockStatus:"请输入激活/锁定状态",
		  loginId:{
	        required: "请输入登录名",
	        minlength: "登录名必需由两个字母组成",
			maxlength: "登录名最大长度为200个字母"
	      },
		  email:{
	        required: "请输入电子邮箱",
	        email: "请输入一个正确的邮箱",
	      },
	      password: {
	        required: "请输入密码",
	        minlength: "密码长度不能小于 6 个字母"
	      },
	      password2: {
	        required: "请输入密码",
	        minlength: "密码长度不能小于 6 个字母",
	        equalTo: "两次密码输入不一致"
	      }
	    },		
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			<c:if test="${empty bean}"> 
			var url = getRootPath()+"/newRmUser/insert?jsguid="+$('#id').val();
			</c:if>
			<c:if test="${not empty bean}"> 
			var url = getRootPath()+"/newRmUser/update?jsguid="+$('#id').val();
			</c:if>
			//提交成功关闭
			submitAjax(url,$("#form-member-add").serialize()); 		    		    		
			layer_close();			
		}
	});
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>